home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-12-03 | 666 b | 39 lines | [TEXT/KAHL] |
- shell(r, num)
- char *r;
- int num;
- {
- char h[10];
- char r0;
- int H,i,j,s;
-
- /*
- The following array is the sequence h[1]=1, h[s+1]=3*h[s]+1
- derived from emprical data. The array has been carried out
- to the limit bounded by num an integer.
-
- Please note the sequence h can greatly effect the sorting time.
- */
-
- h[9]=29524; h[8]=9841; h[7]=3280; h[6]=1093; h[5]=364;
- h[4]=121; h[3]=40; h[2]=13; h[1]=4; h[0]=1;
-
- for (s=0; h[s+2]<num; ++s)
- ;
-
- for ( ;s>=0; --s )
- {
- H = h[s];
- for ( i=H; i<num; i++ )
- {
- r0 = r[i];
- j = i-H;
- while ( r0<r[j] && j>=0 && j<num )
- {
- r[j+H] = r[j];
- j -= H;
- }
- r[j+H] = r0;
- }
- }
- }
-